package com.jzo2o.customer.controller.worker;

import com.jzo2o.common.model.CurrentUserInfo;
import com.jzo2o.common.utils.BeanUtils;
import com.jzo2o.customer.model.domain.BankAccount;
import com.jzo2o.customer.model.dto.request.BankAccountUpsertReqDTO;
import com.jzo2o.customer.model.dto.response.BankAccountResDTO;
import com.jzo2o.customer.service.IBankAccountService;
import com.jzo2o.mvc.utils.UserContext;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController("workerBankAccountController")
@RequestMapping("/worker/bank-account")
@Api(tags = "服务端-银行账户信息相关接口")
public class BankAccountController {
    @Resource
    private IBankAccountService bankAccountService;
    @PostMapping
    @ApiOperation("新增或更新银行账户信息")
    public void queryByServiceProviderId(@RequestBody BankAccountUpsertReqDTO bankAccountUpsertReqDTO){
        CurrentUserInfo currentUserInfo = UserContext.currentUser();
        bankAccountUpsertReqDTO.setId(currentUserInfo.getId());
        bankAccountUpsertReqDTO.setType(currentUserInfo.getUserType());
        bankAccountService.upsert(bankAccountUpsertReqDTO);
    }

    @GetMapping("currentUserBankAccount")
    @ApiOperation("获取当前用户银行账号")
    public BankAccountResDTO queryCurrentUserBankAccount(){
        BankAccount bankAccount = bankAccountService.getById(UserContext.currentUserId());
        return BeanUtils.toBean(bankAccount,BankAccountResDTO.class);
    }

}
